package com.netdisk.controller;

import com.netdisk.dto.LoginDTO;
import com.netdisk.dto.RegisterDTO;
import com.netdisk.dto.StorageStatsDTO;
import com.netdisk.dto.UserDTO;
import com.netdisk.service.UserService;
import com.netdisk.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户控制器
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public Result<UserDTO> register(@RequestBody @Validated RegisterDTO registerDTO) {
        UserDTO userDTO = userService.register(registerDTO);
        return Result.success("注册成功", userDTO);
    }

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public Result<UserDTO> login(@RequestBody @Validated LoginDTO loginDTO) {
        UserDTO userDTO = userService.login(loginDTO);
        return Result.success("登录成功", userDTO);
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/info")
    public Result<UserDTO> getUserInfo(@RequestParam Integer userId) {
        UserDTO userDTO = userService.getUserInfo(userId);
        return Result.success(userDTO);
    }

    @ApiOperation("获取存储统计信息")
    @GetMapping("/storage/stats")
    public Result<StorageStatsDTO> getStorageStats(@RequestParam Integer userId) {
        StorageStatsDTO storageStatsDTO = userService.getStorageStats(userId);
        return Result.success(storageStatsDTO);
    }
} 